package com.terrier.ui.skins.defaults
{
	import com.terrier.ui.skins.IWxButtonSkin;
	
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	public class WxButtonAnimationSkin implements IWxButtonSkin
	{
		protected var bg:Sprite;
		
		protected var _background:BitmapData;
		
		protected var _upBg:DisplayObject;
		
		protected var _overBg:DisplayObject;
		
		protected var _downBg:DisplayObject;
		
		protected var _disabledBg:DisplayObject;
		
		public function WxButtonAnimationSkin()
		{
			bg = new Sprite();
			
			_upBg = new Button_upSkinAnimation();
			
			_overBg = new Button_overSkin();
			
			_downBg = new Button_downSkin();
			
			_disabledBg = new Button_disabledSkin();
			
			bg.addChild(_upBg);
			
			_background = new Button_background();
			
			drawBackground();
		}
		
		public function get upBg():DisplayObject
		{
			bg.removeChildAt(0);
			bg.addChild(_upBg);
			return bg;
		}
		
		public function get overBg():DisplayObject
		{
			bg.removeChildAt(0);
			bg.addChild(_overBg);
			return bg;
		}
		
		public function get downBg():DisplayObject
		{
			bg.removeChildAt(0);
			bg.addChild(_downBg);
			return bg;
		}
		
		public function get disabledBg():DisplayObject
		{
			bg.removeChildAt(0);
			bg.addChild(_disabledBg);
			return bg;
		}
		
		public function get customLayout():Boolean
		{
			return false;
		}
		
		public function get width():Number
		{
			return _upBg.width;
		}
		
		public function set width(value:Number):void
		{
			_upBg.width = _overBg.width = _downBg.width = _disabledBg.width = value;
			drawBackground();
		}
		
		public function get height():Number
		{
			return _upBg.height;
		}
		
		public function set height(value:Number):void
		{
			_upBg.height = _overBg.height = _downBg.height = _disabledBg.height = value;
			drawBackground();
		}
		
		private function drawBackground():void
		{
			bg.graphics.clear();
			bg.graphics.beginBitmapFill(_background, null, true);
			bg.graphics.drawRect(0, 0, _upBg.width, _upBg.height);
			bg.graphics.endFill();
		}
	}
}